package com.atomscat.lottery.repository;

import com.atomscat.lottery.entity.db.LotteryUserEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface LotteryUserRepository extends JpaRepository<LotteryUserEntity, Long> {

    @Query(value = "SELECT o.* FROM lottery_user o JOIN lottery_activity_user u ON o.id = u.user_id WHERE " +
            "u.activity_id = :activityId", nativeQuery = true)
    Page<LotteryUserEntity> findByActivityId(@Param("activityId") Long activityId, Pageable pageable);

}
